//判断是否是PC端
function IsPC() {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
        "SymbianOS", "Windows Phone",
        "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
        if (userAgentInfo.indexOf(Agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}
//防抖函数
function debounce (fn,delay){
    let timer = null
    return function (){
        if(timer){
            clearTimeout(timer)
        }
        timer =  setTimeout(fn,delay)
    }
}
//topBtn
function scrollTop(){
    let $top = $("#toTopBtn")
    if($top.is(":not(:animated)")){
        if ($(document).scrollTop() > 1200) {
            $top.fadeIn(300)
        } else{
            $top.fadeOut(300)
        }
    }
    
}
$(function() {
    if(!IsPC()){return}
    $(document.body).append(
        `
        <div id="toTopBtn">
            <img src="https://gamesres.ultralisk.cn/ulwebfile/view/static/img/topBtn.png" alt="" style="width:90px">
        </div>
        `
    )
    $(document).scroll(debounce(scrollTop,300))
    $("#toTopBtn").click(() => {
        $("html").animate({ scrollTop: 0 }, 300)
    })
})
